<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title> 型号均价</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/webapp/js/common/jquery.global.settings.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
    <div class="easyui-panel" style="border:none;">
        <div class="nav" id="nav"></div>
        <div class="easyui-panel" style="border:none;">
            <form id="ff">
                <div style="margin-bottom:10px;">
                    <label class="item-label">第一组：</label>
                    <select name="group1" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                        <option value="">--请选择--</option>
                        <option value="OK">确认</option>
                        <option value="DISABLE" >未确认</option>
                    </select>
                    <label class="item-label">第二组：</label>
                    <select name="group2" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                        <option value="">--请选择--</option>
                        <option value="OK">确认</option>
                        <option value="DISABLE" >未确认</option>
                    </select>
                    <label class="item-label">第三组：</label>
                    <select name="group3" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                        <option value="">--请选择--</option>
                        <option value="OK">确认</option>
                        <option value="DISABLE" >未确认</option>
                    </select>
                    <a href="javascript:void(0);" style="margin-left:40px;width:80px;" class="easyui-linkbutton c8" onclick="searchBy()">查询</a>
                </div>
                <!--<div style="margin-bottom:10px;margin-left: 10px;text-align:left;">-->
                <!--<span id="totalInfo" style="margin-right:10px;font-weight: bold;font-size: 16px;"></span>-->
                <!--</div>-->
            </form>
        </div>
        <div class="table-wrapper">
            <table id="datagrid" class="easyui-datagrid" data-options="fitColumns:true,scrollbarSize:0"  style="max-height: 710px;">
                <thead>
                <tr>


                    <th data-options="field:'code',align:'center'" width="80">代码</th>
                    <th data-options="field:'name',align:'center'" width="150">型号</th>
                    <th data-options="field:'categoryName',align:'center'" width="80">品类</th>
                    <th data-options="field:'group1',align:'center',formatter:statusFormatter"  width="60">第一组</th>
                    <th data-options="field:'group2',align:'center',formatter:statusFormatter" width="60">第二组</th>
                    <th data-options="field:'group3',align:'center',formatter:statusFormatter" width="60">第三组</th>
                    <th data-options="field:'status',align:'center',formatter:statusFormatter" width="60">总进度</th>
                    <th data-options="field:'updateTime',align:'center'" width="150">修改时间</th>
                    <th data-options="field:'operateUser',align:'center'" width="60">操作人</th>
                    <th data-options="field:'action',align:'center',formatter:actions" width="180">操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript">
    var id;
    $(function(){
        id = getQueryParameter("id");
        setNav();
        initUserCategorySelect("categorySelect",function (code) {
            initModelSearchSelect("propCode","metadatavalue",code);
        });
        initBrandSelect("brandSelect");
        initProvinceSelect("provinceSelect", provinceChange);
        initMonthWeek("monthLabel","weekLabel");
        $("#datagrid").datagrid({
            // pagination:true,
            rownumbers:true
        });
    });
    function provinceChange(provinceCode){
        initCitySelect("citySelect", provinceCode);
        $.ajax({
            url:config.url+'/dictionary/getCityByProvince/'+provinceCode,
            type:"get",
            xhrFields:{withCredentials:true},
            success:function (data) {
                if(data){
                    $(data).map(function(index,item){
                        item['text'] = item.name;
                    });
                    data.unshift({"text":"-请选择-","code":""});
                    $("#citySelect").combobox({
                        "textFiled":"text",
                        "valueField":"code",
                        "data":data
                    });
                }
            },
            error:function(XMLHttpRequest,textStatus,errorThrown){
            }
        })
    }

    function searchBy(){
        var data = getFormData(document.getElementById("ff"));
        data.reportType=window.parent.workMode.toUpperCase();
        var tj="?id=" + id
        if(data.group1){
            tj=tj+"&gropu1="+data.group1;
        }
        if(data.group2){
            tj=tj+"&gropu2="+data.group2;
        }
        if(data.group3){
            tj=tj+"&gropu3="+data.group3;
        }
        $.ajax({
            url:config.url + "/modelConfirm/model"+tj,
            type:"GET",
            data:transfer(data),

            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function () {
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"数据加载中..."
                });
            },
            success:function(data){
                var totalInfo = '';
                // console.log(Object.keys(data))
                if(null != data &&data.length>0 ){
                    $("#datagrid").datagrid({data: data}).datagrid("getPager");
                    $.messager.progress("close");
                }else {
                    $("#datagrid").datagrid({data: []}).datagrid("getPager");
                    $.messager.progress("close");
                }
            },
            error:function(data){
                console.log(data);
                $.messager.progress("close");
            }
        });
    }
    function actions(val, row){
        var disableBtnText = row.entityStatus=='OK'?'禁用':"启用";
        return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
            "style='width:60px;' onclick='edit(\""+row.id+"\",\""+row.categoryCode+"\")'>修改</a>&nbsp;&nbsp;";
    }
    function edit(mid,categoryCode){
        window.parent.addTab("修改型号", "/webapp/pages/product/modelConfirm/add.html?id="+mid+"&categoryCode="+categoryCode+"&rwId="+id);
    }
    function formatCount_01(val, row) {
        if(row.avgPriceList[0]>row.avgPriceList[1]){
            return style('+' + ~~(row.avgPriceList[0]-row.avgPriceList[1]), 'yes');
        }else if(row.avgPriceList[0]<row.avgPriceList[1]){
            return style('-' + ~~(row.avgPriceList[1]-row.avgPriceList[0]), 'no');
        }else{
            return '--';
        }
    }
    function formatCount_05(val, row) {
        if(row.avgPriceList[0]>row.avgPriceList[5]){

            return style('+' + ~~(row.avgPriceList[0]-row.avgPriceList[5]), 'yes');
        }else if(row.avgPriceList[0]<row.avgPriceList[5]){
            return style('-' + ~~(row.avgPriceList[5]-row.avgPriceList[0]), 'no');
        }else{
            return '--';
        }
    }
    function style(text, flag){
        if('yes'==flag){
            return '<span style="font-size: 14px;font-weight: bold;color: red;">' + text + '</span>';
        }else if('no'==flag){
            return '<span style="font-size: 14px;font-weight: bold;color: green;">' + text + '</span>';
        }
        return text;
    }


    function initChannelSelectshare(channelSelectId, mallSelectId, initCallback){
        var dtd = $.Deferred();
        $.ajax({
            url:config.url +"/channel/getAll",
            type:"get",
            xhrFields:{withCredentials:true},
            success:function (data) {
                if(data){
                    data.unshift({"name":"-请选择-","code":"-请选择-","selected":true});
                    $("#"+channelSelectId).combobox({
                        "textField":"code",
                        "valueField":"code",
                        "panelHeight":"150",
                        "data":data
                    });
                    dtd.resolve();
                    // 回调函数
                    if(typeof initCallback === "function"){
                        if(data.length>=2){
                            $("#"+channelSelectId).combobox('select', data[1]['code']);
                        }
                        initCallback();
                    }
                }
            },
            error:function(XMLHttpRequest,textStatus,errorThrown){
                dtd.reject();
            }
        });
        return dtd.promise();
    }
    $("#ff").keydown(function (event) {
        var e = event || window.event;
        var keyCode = e.keyCode || e.which;
        if(keyCode=="13"){
            searchBy();
        }
    });

    function initGroup(propCode,metadatawrapper,propValue){
        var data=[{"name":"-请选择-","code":""},{"name":"年份","code":"year"},{"name":"月份","code":"month"}];
        data.push({"name":"周度","code":"week"})
        data.push({"name":"报告类型","code":"reportType"})
        data.push({"name":"top榜单","code":"top"})
        $("#"+propCode).combobox({
            textField:"name",
            valueField:"code",
            panelHeight:"200px",
            data:data,
            onChange:function (newValue,oldValue) {
                if("reportType"==newValue){
                    inner = "<select class='easyui-combobox' name='sdpropValue1' data-options=\"panelHeight:'auto'\" style='width:200px;'data-options='multiple:true'>";
                    inner += "<option value=\"MONTH\">月报</option>\n" +
                        "                        <option value=\"WEEK\" >周报</option>\n" +
                        "                        <option value=\"ONLINE\" >电商(周)</option>\n" +
                        "                        <option value=\"ONLINE_M\">电商(月)</option>\n"+
                        "                        <option value=\"PDK_W\">拼抖快(周)</option>\n"+
                        "                        <option value=\"PDK_M\">拼抖快(月)</option>\n";
                    inner += "</select>"
                }else{
                    //根据是否有值来决定是下拉框还是文本框
                    var inner = "";
                    var proValueName = propValue || "propValue1";
                    inner = "<input type='text' class='easyui-textbox' name='"+proValueName+"' style='width:200px' prompt='请输入值'/>"
                }

                $("#"+metadatawrapper).html(inner);
                $.parser.parse($("#"+metadatawrapper));
            }
        });
    }
</script>
</body>
</html>